#include <iostream>
#include <fstream>
#include <ctime>

void bubbleSort(int arr[], size_t size) {
    for (size_t i = 0; i < size - 1; ++i) {
        for (size_t j = 0; j < size - 1 - i; ++j) {
            if (arr[j] > arr[j + 1]) {
                std::swap(arr[j], arr[j + 1]);
            }
        }
    }
}

void readFile(const std::string& fileName, int arr[], size_t& size) {
    std::ifstream file(fileName);
    size = 0;
    int num;
    while (file >> num) {
        arr[size++] = num;
    }
    file.close();
}

void measureTime(int arr[], size_t size, const std::string& label) {
    clock_t startTime = clock();
    int* copy = new int[size];
    std::copy(arr, arr + size, copy);
    bubbleSort(copy, size);
    clock_t endTime = clock();
    double duration = static_cast<double>(endTime - startTime) / CLOCKS_PER_SEC * 1000.0;
    std::cout << label << " " << static_cast<int>(duration) << " milliseconds" << std::endl;
    delete[] copy;
}

int main() {
    const size_t MAX_SIZE = 10000; // Предполагаем максимальный размер массива
    int m1Sorted[MAX_SIZE];
    size_t sizeM1Sorted;
    readFile("m1_sorted.txt", m1Sorted, sizeM1Sorted);
    measureTime(m1Sorted, sizeM1Sorted, "m1_sorted");

    int m2Reverse[MAX_SIZE];
    size_t sizeM2Reverse;
    readFile("m2_reverse.txt", m2Reverse, sizeM2Reverse);
    measureTime(m2Reverse, sizeM2Reverse, "m2_reverse");

    int m3Shuffle[MAX_SIZE];
    size_t sizeM3Shuffle;
    readFile("m3_shuffle.txt", m3Shuffle, sizeM3Shuffle);
    measureTime(m3Shuffle, sizeM3Shuffle, "m3_shuffle");

    return 0;
}
